package com.datamation.swadeshi.view;



import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.datamation.swadeshi.R;
import com.datamation.swadeshi.adapter.SetTitleAdapter;

public class FragmentInventoryControlAdjustment extends Fragment{

	View vadjAddview;
	ListView lvAdjAddList;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		vadjAddview = inflater.inflate(R.layout.inventory_control_adjustment_addition, container, false);
		
		lvAdjAddList = (ListView) vadjAddview.findViewById(R.id.lvPhoneAdjustmentList);
		
		getActivity().getActionBar().removeAllTabs();
		getActivity().getActionBar().setNavigationMode(0);
		setHasOptionsMenu(true);
		
		SetTitleAdapter adapter =  new SetTitleAdapter();
		adapter.createCutomActionBarTitle("Adjustment Addition", getActivity());
		
		lvAdjAddList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub
				
			}
			
			
		});
		
		vadjAddview.setFocusableInTouchMode(true);
		vadjAddview.requestFocus();
		vadjAddview.setOnKeyListener(new View.OnKeyListener() {
			
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				// TODO Auto-generated method stub
				if (keyCode == KeyEvent.KEYCODE_BACK){
					Toast.makeText(getActivity(),"Back Navigationid is disable", Toast.LENGTH_SHORT).show();
					
					return true;
				}else if(keyCode == KeyEvent.KEYCODE_HOME){
					getActivity().finish();
					return true;
				}else{
					return false;
				}
				
			}
		});
		
		return vadjAddview;
	}

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		// TODO Auto-generated method stub
		for(int i = 0; i < menu.size(); ++i){
			menu.removeItem(menu.getItem(i).getItemId());
		}
		
		inflater.inflate(R.menu.frag_invoice_phone_menu, menu);
		
		super.onCreateOptionsMenu(menu, inflater);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if(item.getItemId() == R.id.action_invoice_phone_new){
			FragmentTransaction transaction = getFragmentManager().beginTransaction();
			transaction.replace(R.id.frame_container, new FragmentSalesManagementPreSales());
			transaction.addToBackStack(null);
			transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			transaction.commit();
		}
		return super.onOptionsItemSelected(item);
	}

	

	
	
}
